package com.gszkc.controller.user;


import com.gszkc.dto.ShoppingCartDTO;
import com.gszkc.entity.ShoppingCart;
import com.gszkc.result.Result;
import com.gszkc.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车相关接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车数据")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车：{}",shoppingCartDTO);
        shoppingCartService.addshoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车数据")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCartList = shoppingCartService.showShoppingCart();
        return Result.success(shoppingCartList);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车数据")
    public Result clean(){
        shoppingCartService.cleanShopping();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中的一个数据")
    public Result cleanOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.cleanOneShopping(shoppingCartDTO);
        return Result.success();
    }
}
